package cn.mayaslight.wechat.api;

import org.apache.http.Header;

import cn.mayaslight.common.annotation.HttpWithEntity;
import cn.mayaslight.common.annotation.HttpWithHeader;
import cn.mayaslight.common.annotation.HttpWithParam;
import cn.mayaslight.common.param.IParamIn;
import cn.mayaslight.common.springbean.APICaller;
import cn.mayaslight.common.utils.JsonUtil;
import cn.mayaslight.wechat.api.bean.BaseResult;
import cn.mayaslight.wechat.api.bean.Menu;
import cn.mayaslight.wechat.api.bean.MenuButtons;

public class MenuAPI extends BaseAPI {
	
	public static BaseResult qyMenuCreate(final String accessToken, final String agentid, final String menuJson) {
		return APICaller.call(new IParamIn() {
			
			@HttpWithEntity
			private String _menuJson = menuJson;
			
			@HttpWithHeader
			private Header header = jsonHeader;
			
			@HttpWithParam("access_token")
			private String _accessToken = accessToken;
			
			@HttpWithParam("agentid")
			private String _agentid = agentid; 
			
			public String getApiKey() {
				return APICaller.HTTP_URL_POST_PREFIX + QY_BASE_URI + "/cgi-bin/menu/create";
			}
		}, BaseResult.class);
	}
	
	public static BaseResult menuCreate(final String accessToken, final String menuJson) {
		return APICaller.call(new IParamIn() {
			
			@HttpWithEntity
			private String _menuJson = menuJson;
			
			@HttpWithHeader
			private Header header = jsonHeader;
			
			@HttpWithParam("access_token")
			private String _accessToken = accessToken;
			
			public String getApiKey() {
				return APICaller.HTTP_URL_POST_PREFIX + BASE_URI + "/cgi-bin/menu/create";
			}
		}, BaseResult.class);
	}

	public static BaseResult qyMenuCreate(String access_token, String agentid, MenuButtons menuButtons) {
		String str = JsonUtil.toJSONString(menuButtons);
		return qyMenuCreate(access_token, agentid, str);
	}

	public static Menu menuGet(final String accessToken) {
		return APICaller.call(new IParamIn() {
			
			@HttpWithParam("access_token")
			private String _accessToken = accessToken;
			
			public String getApiKey() {
				return APICaller.HTTP_URL_POST_PREFIX + BASE_URI + "/cgi-bin/menu/get";
			}
		}, Menu.class);
	}

}